package cn.stylefeng.guns.modular.movies.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;

import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;

import cn.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;

import cn.stylefeng.guns.modular.system.model.Medicaltype;
import cn.stylefeng.guns.modular.system.model.Moviestype;
import cn.stylefeng.guns.modular.movies.service.IMoviestypeService;

/**
 * 影视期刊控制器
 *
 * @author fengshuonan
 * @Date 2020-06-21 00:41:02
 */
@Controller
@RequestMapping("/moviestype")
public class MoviestypeController extends BaseController {

    private String PREFIX = "/movies/moviestype/";

    @Autowired
    private IMoviestypeService moviestypeService;

    /**
     * 跳转到影视期刊首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "moviestype.html";
    }

    /**
     * 跳转到添加影视期刊
     */
    @RequestMapping("/moviestype_add")
    public String moviestypeAdd() {
        return PREFIX + "moviestype_add.html";
    }

    /**
     * 跳转到修改影视期刊
     */
    @RequestMapping("/moviestype_update/{moviestypeId}")
    public String moviestypeUpdate(@PathVariable Integer moviestypeId, Model model) {
        Moviestype moviestype = moviestypeService.selectById(moviestypeId);
        model.addAttribute("item",moviestype);
        LogObjectHolder.me().set(moviestype);
        return PREFIX + "moviestype_edit.html";
    }

    /**
     * 获取影视期刊列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
    	EntityWrapper<Moviestype> wrapper = new EntityWrapper<Moviestype>();
    	wrapper.like("goods_name", condition).or()
    	.like("id", condition);
        return moviestypeService.selectList(wrapper);
    }

    /**
     * 新增影视期刊
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Moviestype moviestype) {
        moviestypeService.insert(moviestype);
        return SUCCESS_TIP;
    }

    /**
     * 删除影视期刊
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer moviestypeId) {
        moviestypeService.deleteById(moviestypeId);
        return SUCCESS_TIP;
    }

    /**
     * 修改影视期刊
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Moviestype moviestype) {
        moviestypeService.updateById(moviestype);
        return SUCCESS_TIP;
    }

    /**
     * 影视期刊详情
     */
    @RequestMapping(value = "/detail/{moviestypeId}")
    @ResponseBody
    public Object detail(@PathVariable("moviestypeId") Integer moviestypeId) {
        return moviestypeService.selectById(moviestypeId);
    }
    
    @InitBinder
   	public void initBinder(WebDataBinder binder) {
   	    DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
   	    binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));        
   	}
}
